﻿<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="AddHos.aspx.cs" Inherits="HZ.Supervise.Web.Meet.AddHos" %>

<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
    <title></title>
    <link href="../Style/global.css" rel="stylesheet" /> 
    <script src="../Scripts/jquery.min.js"></script>

    <script type="text/javascript"> 
        var rids = "";//记录页面上的行号 保存时需要
        function findObj(theObj, theDoc) {
            var p, i, foundObj;
            if (!theDoc) theDoc = document;
            if ((p = theObj.indexOf("?")) > 0 && parent.frames.length)
            { theDoc = parent.frames[theObj.substring(p + 1)].document; theObj = theObj.substring(0, p); } if (!(foundObj = theDoc[theObj]) && theDoc.all) foundObj = theDoc.all[theObj]; for (i = 0; !foundObj && i < theDoc.forms.length; i++) foundObj = theDoc.forms[i][theObj]; for (i = 0; !foundObj && theDoc.layers && i < theDoc.layers.length; i++) foundObj = findObj(theObj, theDoc.layers[i].document); if (!foundObj && document.getElementById) foundObj = document.getElementById(theObj); return foundObj;
        }

        //添加一行
        function AddSignRow() {
            if (document.getElementById("SignFrame").rows.length > 10) {
                alert("每次操作不大于10项!");
            }
            else {
                //读取最后一行的行号，存放在txtTRLastIndex文本框中
                var txtTRLastIndex = findObj("txtTRLastIndex", document);
                var rowID = parseInt(txtTRLastIndex.value);

                var signFrame = findObj("SignFrame", document);
                //添加行
                var newTR = signFrame.insertRow(signFrame.rows.length);
                newTR.id = "SignItem" + rowID;

                //添加列:搜素框
                var newNameTD = newTR.insertCell(0);
                //添加列内容
                newNameTD.innerHTML = "<input name='SS" + rowID + "' id='SS" + rowID + "' type='text' size='15' maxlength='25' onkeyup='onHos(" + rowID + ")'/>";
            
                //添加列:参会单位
                var newNameTD = newTR.insertCell(1);
                //添加列内容
                newNameTD.innerHTML = "<select name='ShowHos" + rowID + "' id='ShowHos" + rowID + "' style='width:200px'></select>";
         
                //添加列:姓名
                var newNameTD = newTR.insertCell(2);
                //添加列内容
                newNameTD.innerHTML = "<input name='Name" + rowID + "' id='Name" + rowID + "' type='text' size='20' maxlength='25'/>";

                //添加列:性别
                var newEmailTD = newTR.insertCell(3);
                //添加列内容
                newEmailTD.innerHTML = "<input name='XB" + rowID + "' id='XB" + rowID + "' type='text' size='20' maxlength='1'/>";

                //添加列:职务
                var newTelTD = newTR.insertCell(4);
                //添加列内容
                newTelTD.innerHTML = "<input name='Postion" + rowID + "' id='Postion" + rowID + "' type='text' size='20' maxlength='25'/>";

                //添加列:联系电话(手机)
                var newMobileTD = newTR.insertCell(5);
                //添加列内容
                newMobileTD.innerHTML = "<input name='TelNo" + rowID + "' id='TelNo" + rowID + "' type='text' size='20' maxlength='11'/>";

                //添加列:是否住宿
                var newCompanyTD = newTR.insertCell(6);
                //添加列内容
                newCompanyTD.innerHTML = "<input name='IsZS" + rowID + "' id='IsZS" + rowID + "' type='text' size='20' maxlength='1'/>";
                 
                //添加列:删除按钮
                var newDeleteTD = newTR.insertCell(7);
                //添加列内容
                newDeleteTD.innerHTML = "<div align='center' style='width:40px'><a href='javascript:;' style='color:#3399ff' onclick=\"DeleteSignRow('SignItem" + rowID + "')\">删除</a></div>";
                  
                rids+=rowID+",";//拼接记录行号

                //将行号推进下一行
                txtTRLastIndex.value = (rowID + 1).toString(); 
            } 
        }

        //删除指定行
        function DeleteSignRow(rowid) {
            var signFrame = findObj("SignFrame", document);
            var signItem = findObj(rowid, document);

            //获取将要删除的行的Index
            var rowIndex = signItem.rowIndex;

            rids=rids.toString().replace(rowIndex+",","");//移除删减的行号

            //删除指定Index的行
            signFrame.deleteRow(rowIndex);
        }

         
        //获取医院数据
        $(function () {
            rids="1,";//页面首次加载赋值
            var uslstr="GetPara.ashx?type=get&mid=<%=mid%>";
            $.ajax({
                url: uslstr,
                type: 'GET',
                dataType: 'json',
                timeout: 3000,
                cache: false,
                beforeSend: LoadFunction, //加载执行方法      
                error: erryFunction,  //错误执行方法      
                success: succFunction //成功执行方法      
            })
            function LoadFunction() {
                $("#list").html('加载中...');
            }
            function erryFunction() {
                alert("error");
            }
            function succFunction(tt) { 
                $("#HosName1").empty();
                var json = eval(tt); //数组   
                $.each(json, function (index, item) { 
                    //循环获取数据    
                    var Id = json[index].HospitalID; 
                    var Name = json[index].HospitalName;   
                    $("#HosName1").append("<option value='" + Id + "'>" + Name + "</option>");//prepend 
                });
            }
        });
          
        //保存当前页面数据
        function SavePara() { 
            var parameter = {};   
            var arrayid="";
            if (rids=="1,") //只有开始的一行
            {
                arrayid="1";
                parameter["ids"]="1";
            }
            else {
                var strs = rids.toString().substring(0, rids.length - 1);
                arrayid = strs.split(',');
                parameter["ids"] = strs;
            }
 
            for (var i = 0; i < arrayid.length; i++) {
                var hos = $("#ShowHos" + arrayid[i]);
                var name = $("#Name" + arrayid[i]).val().trim();
                var xb = $("#XB" + arrayid[i]).val().trim();
                var postion = $("#Postion" + arrayid[i]).val().trim();
                var telno = $("#TelNo" + arrayid[i]).val().trim();
                var iszs = $("#IsZS" + arrayid[i]).val().trim();
                 
                if (hos.val() == "" || hos.val() == "0" || hos.val() == null) {
                    alert("参会单位为空");
                    return;
                }
                if (name=="" || xb=="" || postion=="" || telno=="" || iszs=="") {
                    alert("当前页面均为必填项，请完善信息再保存");
                    return;
                }
                if (xb!="男" && xb!="女") { 
                    alert("性别请填男或女");
                    return;
                }
                //手机号码格式判断
                if (telno.length != 11) {
                    alert("请确认手机号码无误");
                    return;
                }

                if (iszs!="是" && iszs!="否") { 
                    alert("是否住宿请填是或否");
                    return;
                } 
             
                parameter["hd"+arrayid[i]] = hos.val();//医院ID 
                parameter["hm"+arrayid[i]] = hos.find("option:selected").text();//医院Name
                parameter["xm"+arrayid[i]] = name;//姓名
                parameter["xb"+arrayid[i]] = xb; //性别
                parameter["zw"+arrayid[i]] = postion;//职务
                parameter["dh"+arrayid[i]] = telno;//电话
                parameter["zs"+arrayid[i]] = iszs;//住宿 
            }

            var usl2="GetPara.ashx?type=save&mid=<%=mid%>";
            $.ajax({
                url: usl2,
                type: 'POST',
                dataType: 'json',
                data: parameter,
                timeout: 3000,
                cache: false,
                error: function () {
                    alert("error");
                },
                success: function (data) {
                    if (data == 1) {
                        window.location.href = "CHRYList.aspx?mid=<%=mid%>";
                    }
                    else if (data == 0) {
                        alert("保存失败");
                    }
                    else if (data == 9) {
                        alert("超出上限人数，保存失败");
                    }
                    else {

                    }
                }
            });
            
        }

        //搜索框查询医院名称
        function onHos(objid) {
            var hos = $("#HosName1");//医院集合 
            var ss = $("#SS" + objid).val().trim();//搜索框的值 
            if (ss.length > 1) {//搜索1个字以上
                $("#ShowHos" + objid).empty();
                $("#HosName1 option").each(function () {
                    if ($(this).text().indexOf(ss) >= 0) {
                        var sid = $(this).val();
                        var sname = $(this).text();
                        $("#ShowHos" + objid).append("<option value='" + sid + "'>" + sname + "</option>");
                    }
                });
                
                $("#ShowHos" + objid).prepend("<option value='0'>请选择</option>");
            } 
        }
         
    </script>
</head>
<body>
    <form id="form1" runat="server">  
        <select id="HosName1" name="HosName1" style="width:200px;display:none;">  
            <option value="">此处有大用</option>
        </select>  
                 
        <table width="90%" border="0" cellpadding="2" cellspacing="1" id="SignFrame" style="margin-top:20px;">
            <tr id="trHeader"> 
                <td width="100" align="center">搜索医院</td>
                <td width="200" align="center">参会单位</td>  
                <td width="120" align="center">姓名</td>
                <td width="120" align="center">性别</td>
                <td width="120" align="center">职务</td>
                <td width="120" align="center">手机号码</td>
                <td width="120" align="center">是否安排住宿</td>
                <td width="60"  align="center">&nbsp;</td>
            </tr>
            <tr id="SignItem1"> 
                <td>
                    <input name="SS1" id="SS1" type="text" size="15" maxlength="25" onkeyup="onHos(1)" placeholder="医院搜索框"/>
                </td>
                <td>  
                    <select id="ShowHos1" name="ShowHos1" style="width:200px">  
                    </select>  
                </td>  
                <td>
                    <input name="Name1" id="Name1" type="text" size="20" maxlength="25" /></td>
                <td>
                    <input name="XB1" id="XB1" type="text" size="20" maxlength="1" placeholder="请填写男或女"/></td>
                <td>
                    <input name="Postion1" id="Postion1" type="text" size="20" maxlength="25" /></td>
                <td>
                    <input name="TelNo1" id="TelNo1" type="text" size="20" placeholder="请填写手机号码" maxlength="11" /></td>
                <td>
                    <input name="IsZS1" id="IsZS1" type="text" size="20" placeholder="请填写是或否" maxlength="1" /></td>
                <td>&nbsp;</td>
            </tr>
        </table> 
        <div class="listctrl">
            <input type="button" name="AddFZR" value="添加一行" onclick="AddSignRow()" class="btn"/>&nbsp;&nbsp;&nbsp;&nbsp;
            <input name='txtTRLastIndex' type='hidden' id='txtTRLastIndex' value="2" />
            <input type="button" name="btnAdd" value="保存当前页面" onclick="SavePara()" class="btn" style="width:120px"/>&nbsp;&nbsp;&nbsp;&nbsp;
            <asp:Button ID="btnret" runat="server" Text="返 回" CssClass="btn" OnClick="btnret_Click"/>
        </div>
        <div class="listip">
        <ul>
            <li>说明：<span style="color:Red">1、在每行的医院搜索框内，输入医院名称，参会单位中会显示相应的结果供选择。<br />
                &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;2、输入医院名称时，确保医院名称连续。<br />
                &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;3、若参会单位中无结果显示，每次输完医院名称后，后面打个空格。 
                   </span></li>
        </ul>
    </div>
    </form>
</body>
</html>
